package cc.mrbird.febs.power.controller;


import cc.mrbird.febs.common.utils.R;
import cc.mrbird.febs.power.entity.AppInfo;
import cc.mrbird.febs.power.service.IAppInfoService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author MrBird
 */
@RestController
@RequestMapping("/power/app-info")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AppInfoController {

    private final IAppInfoService iAppInfoService;

    /**
     * 分页查询
     * @param page
     * @param appInfo
     * @return
     */
    @GetMapping("/page")
    public R getAppInfoByPage(Page page,AppInfo appInfo) {
        return R.ok(iAppInfoService.page(page, Wrappers.<AppInfo>lambdaQuery()
                .like(appInfo.getAppDataBaseName()!=null,AppInfo::getAppDataBaseName,appInfo.getAppDataBaseName())
                .like(appInfo.getAppName()!=null,AppInfo::getAppName,appInfo.getAppName())));
    }

    /**
     * 获取所有系统数据
     * @return
     */
    @GetMapping
    public R getAppInfoAll() {
        return R.ok(iAppInfoService.list());
    }

    /**
     * 新增系统记录
     * @param appInfo
     * @return
     */
    @PostMapping("/AppInfoAdd")
    public R AppInfoAdd(AppInfo appInfo) {
        return R.ok(iAppInfoService.save(appInfo));
    }

    /**
     * 修改系统记录
     * @param appInfo
     * @return
     */
    @PutMapping("/AppInfoEdit")
    public R AppInfoEdit(AppInfo appInfo) {
        return R.ok(iAppInfoService.updateById(appInfo));
    }

    /**
     * 根据ID删除记录
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public R AppInfoDel(@PathVariable Integer id) {
        return R.ok(iAppInfoService.removeById(id));
    }

    /**
     * 批量删除应用
     * @param ids
     * @return
     */
    @DeleteMapping("/man/{ids}")
    public R AppinfosDel(@PathVariable("ids") List<Integer> ids) {
        return R.ok(iAppInfoService.removeByIds(ids));
    }
}
